package dao

import (
	"ai/internal/db/models"

	"gorm.io/gorm"
)

type QuestionDAO struct {
	db *gorm.DB
}

func NewQuestionDAO(db *gorm.DB) *QuestionDAO {
	return &QuestionDAO{db: db}
}

// AddQuestion adds a new question to the database
func (dao *QuestionDAO) AddQuestion(question *models.Question) error {
	return dao.db.Create(question).Error
}

// GetQuestionsByType retrieves questions of a specific type from the database
func (dao *QuestionDAO) GetQuestionsByType(questionType string) ([]models.Question, error) {
	var questions []models.Question
	err := dao.db.Where("type = ?", questionType).Find(&questions).Error
	return questions, err
}

// ListQuestions retrieves all questions from the database
func (dao *QuestionDAO) ListQuestions() ([]models.Question, error) {
	var questions []models.Question
	err := dao.db.Preload("Answers").Find(&questions).Error
	return questions, err
}

// GetQuestionByID retrieves a question by its ID
func (dao *QuestionDAO) GetQuestionByID(id uint) (*models.Question, error) {
	var question models.Question
	err := dao.db.First(&question, id).Error
	if err != nil {
		return nil, err
	}
	return &question, nil
}

// Add methods for QuestionDAO as needed
